package com.pxene.dmp.mapper;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class CountDomainUserMapper extends
		Mapper<LongWritable, Text, Text, LongWritable> {
	
	private Text resultKey = new Text();
	private LongWritable resultVal = new LongWritable(1l);
	
	@Override
	protected void setup(Context context) throws IOException, InterruptedException {
		Configuration conf = context.getConfiguration();
		// 设置配置文件名
		System.setProperty("config-file", conf.get("config-file"));
	}

	@Override
	protected void map(LongWritable key, Text value, Context context)
			throws IOException, InterruptedException {
		String[] columns = value.toString().split("\\|");
		if (columns.length != 4) {
			return;
		}
		String domain = columns[0];
		String imsi = columns[1];
		String province = columns[2];
		String dataType = columns[3];
		
		resultKey.set(domain + "|" + imsi + "|" + province + "|" + dataType);
		context.write(resultKey, resultVal);
	}

}
